/*
 * File:   DiceAdds.cpp
 * Author: luk
 *
 * Created on March 6, 2015, 10:06 PM
 */

#include <stdlib.h>

#include "RollServiceImpl.h"

SuccessRollResult RollServiceImpl::successRoll(int target) {
    bool success;
    bool critical;

    int roll = dieService.roll(3);
    int margin = abs(roll - target);

    if (roll == 3 || roll == 4) {
        success = critical = true;
    } else if (roll == 18) {
        success = false;
        critical = true;
    } else if (roll == 17) {
        success = false;
        critical = (target <= 15);
    } else {
        success = (roll <= target);
        critical = (margin >= 10);
    }

    return SuccessRollResult(success, critical, roll, target, margin);
}

RollServiceImpl::RollServiceImpl(DieService & dieService) : dieService(dieService) {
}

int RollServiceImpl::damageRoll(int dice, int add) {
    return dieService.roll(dice) + add;
}
